package com.study.flink.word

import org.apache.flink.api.scala.ExecutionEnvironment

/**
  * 批处理
  *
  * @author: stephen.shen
  * @create: 2019-01-25 16:40
  */
object ScalaBatchWordCount {

  def main(args: Array[String]): Unit = {
    val path = "file:///D:\\MyCode\\BigdataWork\\bigdata-study\\study-flink\\src\\main\\resource\\README.txt"

    val env = ExecutionEnvironment.getExecutionEnvironment

    val text = env.readTextFile(path)

    import org.apache.flink.api.scala._

    val counts = text.flatMap(_.toLowerCase.split("\\s"))
      .filter(_.nonEmpty)
      .map((_, 1))
      .groupBy(0)
      .sum(1)

    counts.print()
  }
}
